package com.meicloud.license.infra.controller;

import com.meicloud.license.appl.service.LicenseService;
import com.meicloud.license.appl.vo.LicenseDto;
import com.meicloud.license.appl.vo.LicenseRegisterDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * license对外controller
 *
 * @author zhanghui145
 * @date 2022/1/10 15:34
 * @since 1.0.0
 */
@RestController
public class LicenseController {

    @Resource
    private LicenseService licenseService;

    @PostMapping("/license/custom/register")
    public String generateRegisterCode(@RequestBody LicenseRegisterDto registerDto){
        return licenseService.generateRegisterCode(registerDto);
    }

    @PostMapping("/license/custom/license")
    public String generateLicenseCode(@RequestParam("registerCode") String registerCode){
        return licenseService.generateLicenseCode(registerCode);
    }

    @PostMapping("/license/custom")
    public boolean customRegister(@RequestParam("registerCode") String registerCode,
                                  @RequestParam("licenseCode") String licenseCode){
        return licenseService.register(registerCode, licenseCode);
    }

    @GetMapping("/license/custom")
    public LicenseDto licenseStatus(@RequestParam("customName") String customName,
                                    @RequestParam("ip") String ip,
                                    @RequestParam("sysName") String sysName){
        return licenseService.licenseStatus(customName, ip, sysName);
    }
}
